import request from '../utils/request'

/**
 * 查询文章列表
 * @returns {AxiosPromise}
 */
export const getArticleList = (params) => {
  return request({
    url: 'mp/articles',
    params
  })
}
/**
 * 根据id 删除文章
 * @param id
 * @returns {*}
 */
export const delArticle = (id) => {
  return request({
    method: 'DELETE',
    url: '/mp/articles/' + id
  })
}

/**
 * 添加文章
 * @param data //添加文章的数据
 * @param draft // 判断是添加到文章里边还是添加到草稿
 * @returns {AxiosPromise}
 */

export const addArticle = (data, draft = false) => {
  return request({
    url: '/mp/articles',
    method: 'post',
    data,
    params: {
      draft
    }
  })
}

/**
 * 获取文章详情
 * @param params
 * @returns {AxiosPromise}
 * @constructor
 */
export const ArticleInfo = (params) => {
  return request({
    url: '/mp/articles/' + params
  })
}

export const editArticle = (id, data, draft) => {
  return request({
    url: '/mp/articles/' + id,
    method: 'PUT',
    data,
    params: {
      draft
    }
  })
}
